<?php
class Tb_Clubs extends Models {
    private $_name = "clubs";

    /*
     * Insert
     */
    public function insert($clubs) {
        foreach ($clubs AS $club) {
            $fields = 'name';
            $values = '"'.mysql_escape_string($club['name']).'"';

            $query = 'INSERT IGNORE INTO '.$this->_name.'('.$fields.')
                      VALUES('.$values.')';
            $this->query($query);
        }
    }
    
    /*
     * Insert
     */
    public function insertClub($name) {
        
        $fields = 'name';
        $values = '"' . mysql_escape_string($name) . '"';

        $query = 'INSERT IGNORE INTO ' . $this->_name . '(' . $fields . ')
                      VALUES(' . $values . ')';
        $this->query($query);
        
    }
    

    /*
     * Get all touraments
     */
    public function get($name = NULL) {
        $club = NULL;
        if (!empty($name)) {
            $query = 'SELECT * FROM '.$this->_name.'
                      WHERE name = "'.$name.'"';
            $club = $this->fetchRow($query);
        } else {
            $query = 'SELECT * FROM '.$this->_name;                      
            $clubs = $this->fetchArray($query);
            return $clubs;
        }
        return $club;
    }
}